//
//  CustomTabBarController.m
//  Coco_Music
//
//  Created by 强哥 on 15/6/19.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "CustomTabBarController.h"
#import "PlayingViewController.h"
#import "SearchViewController.h"
#import "RankViewController.h"
#import "CategorViewController.h"
#import "CustomNavigationController.h"
#import "DiscoverViewController.h"
#import "SettingViewController.h"

@interface CustomTabBarController ()

@end

@implementation CustomTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    
    UIButton *changeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    changeButton.frame = CGRectMake( 10, 100, 40, 40);
    [changeButton setImage:[UIImage imageNamed:@"menuUsers.png"] forState:UIControlStateNormal];
    [changeButton addTarget:self action:@selector(changeButton) forControlEvents:UIControlEventTouchUpInside];
    [self.aView addSubview:changeButton];
    
    
    //***
    DiscoverViewController *discoverVC = [[DiscoverViewController alloc]init];
    [self addChildViewController:discoverVC title:@"推荐" Image:@"icn_2@2x.png" selecetImage:@"icn_2@2x.png"];
    [discoverVC release];
    
    RankViewController *rankVC = [[RankViewController alloc]init];
    [self addChildViewController:rankVC title:@"排行" Image:@"mymusci@2x.png" selecetImage:@"mymusci@2x.png"];
    [rankVC release];

    CategorViewController *storageVC = [[CategorViewController alloc]init];
    [self addChildViewController:storageVC title:@"乐库" Image:@"nav_music@2x.png" selecetImage:nil];
    [storageVC release];
    
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    [self addChildViewController:searchVC title:@"搜索" Image:@"tabbarSearch@2x.png" selecetImage:@"tabbarSearch@2x.png"];
    [searchVC release];
    
    
    CustomTabBar *tabBar = [[CustomTabBar alloc]init];
    tabBar.myPlay = self;
    [self setValue:tabBar forKeyPath:@"tabBar"];
    [tabBar release];}



-(void)Present
{
    PlayingViewController *play = [PlayingViewController shareHandleController];
    UINavigationController *naPlay = [[[UINavigationController alloc]initWithRootViewController:play] autorelease];
    
    [self presentViewController:naPlay animated:YES completion:^{
        
    }];
    
}


-(void)changeButton
{
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchVC animated:YES];
}




-(void)rightButton
{
    
       SettingViewController *setVC = [[[SettingViewController alloc]init]autorelease];
    
       UINavigationController *nsSetVC = [[UINavigationController alloc]initWithRootViewController:setVC];
      
        [self presentViewController:nsSetVC animated:YES completion:^{
            
            
        }];
}


-(void)addChildViewController:(UIViewController *)childController title:(NSString *)title Image:(NSString *)image selecetImage:(NSString *)selectImage
{
    
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 40, 40);
   [button setImage:[UIImage imageNamed:@"btn_bar_set@2x.png"] forState:UIControlStateNormal];
   [button addTarget:self action:@selector(rightButton) forControlEvents:UIControlEventTouchUpInside];
    
    childController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    childController.title = title;
    childController.tabBarItem.image = [UIImage imageNamed:image];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSMutableDictionary *text = [NSMutableDictionary dictionary];
    text[NSForegroundColorAttributeName] = [UIColor blueColor];
    NSMutableDictionary *selecctText = [NSMutableDictionary dictionary];
    selecctText[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childController.tabBarItem setTitleTextAttributes:text forState:UIControlStateNormal];
    [childController.tabBarItem setTitleTextAttributes:selecctText forState:UIControlStateSelected];
    CustomNavigationController *Navigation = [[CustomNavigationController alloc]initWithRootViewController:childController];
    Navigation.navigationBar.translucent = NO;
    [self addChildViewController:Navigation];
    [Navigation release];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
